<template>
  <div class="address">
    <van-row>
      <van-col span="24">
        <van-nav-bar
          title="地址管理"
          left-text="返回"
          left-arrow
          @click-left="onClickLeft"
        />
      </van-col>

      <van-col span="24">
        <div class="box">
          <van-address-list
            v-model="chosenAddressId"
            :list="list"
            :disabled-list="disabledList"
            disabled-text="以下地址超出配送范围"
            default-tag-text="默认"
            @add="onAdd"
            @edit="onEdit"
          />
        </div>

        <!-- <van-col span="24">
          <div class="right">
            <van-grid direction="horizontal" :column-num="3">
              <van-grid-item icon="photo-o" text="文字" />
              <van-grid-item icon="photo-o" text="文字" />
              <van-grid-item icon="photo-o" text="文字" />
            </van-grid></div
        ></van-col> -->
      </van-col>
    </van-row>
  </div>
</template>

<script>
import { Toast } from "vant";
import { addressList } from "../../api/address";
export default {
  data() {
    return {
      chosenAddressId: "1",
      list: [],
      disabledList: [
        {
          id: "3",
          name: "刘海柱",
          tel: "1320000000",
          address: "黄胶鞋，七分裤，职业法师刘海柱",
        },
      ],
    };
  },
  computed: {},
  watch: {},

  methods: {
    //初始化地址列表
    async initAddress() {
      const result = await addressList({
        per: 5,
        page: 1,
      });
      console.log(result);
      // this.list = result.addresses;
      var arr = [];
      for (var i = 0; i < result.addresses.length; i++) {
        arr.push({
          id: result.addresses[i]._id,
          name: result.addresses[i].user,
          tel: result.addresses[i].mobile,
          address: result.addresses[i].regions + result.addresses[i].address,
          isDefault: result.addresses[i].isDefault || false,
        });
        console.log(arr[i].name);
      }
      this.list = arr;
      console.log(1111111111, this.list);
    },
    onClickLeft() {
      this.$router.go(-1);
    },
    onAdd() {
      this.$router.push("/adaddress/");
      Toast("新增地址");
    },
    onEdit(item, index) {
      this.$router.push("/adaddress/");
      Toast("编辑地址:" + index);
    },
  },
  created() {
    this.initAddress();
  },
  mounted() {},
  components: {},
};
</script>
<style scoped>
</style>